import {Form, message, Modal} from 'antd';
import ProForm, {ProFormDigit, ProFormText} from "@ant-design/pro-form";
import {PutEdit,getEditInfo} from "@/services/ant-design-pro/order";
import {useEffect, useState} from "react";


const OrderEditModal = (props) => {
    const {visible,setVisible,refreshEdit,id} = props;
    const [editData,setEditData] = useState({})
    const [payPrice,setPayPrice] = useState('')
    const [form] = Form.useForm()
  useEffect(async ()=>{
        let data = await getEditInfo(id)
        setEditData(data)
    },[id])
    return (
        <Modal
            visible={ visible  }
            onCancel={()=>{ setVisible(false) }}
            title="修改订单"
            onOk={()=>{
                if (payPrice > editData.pay_price){
                    message.error('退款金额不能大于实际金额')
                }else {
                    form.validateFields().then( async value => {
                        refreshEdit()
                        await PutEdit(id, {...value})
                        message.success('成功修改!')
                        setTimeout(()=>{
                            setVisible(false)
                        },1000)
                    })
                }
            }}
        >
        { editData.pay_price ?
            <ProForm
            form={form}
            submitter={false}
            initialValues={editData}
        >
            <ProFormText placeholder={editData.order_number} disabled label="订单编号:"/>
            <ProFormDigit placeholder={editData.total_price} width="sm" disabled label="商品总价:"/>
            <ProFormDigit placeholder={editData.total_postage} width="sm" disabled label="原始邮费:"/>
            <ProFormDigit placeholder={editData.pay_postage} width="sm" disabled label="实际支付原始邮费:"/>
            <ProFormDigit
                name="pay_price"
                width="sm"
                label="实际支付金额:"
                onChange={(value)=>{
                    setPayPrice(value)
                }}
            />
            <ProFormDigit name="gain_integral" width="sm" max={10000} label="赠送积分:"/>
        </ProForm>
        : null
        }

        </Modal>
    );
};

export default OrderEditModal;













































































































